package com.erplan.studentmgt.desktop.elements;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

import com.erplan.studentmgt.desktop.StudentMgt;

public class AboutApp {
	public static void createAboutDialog(Shell shell, Display display){
		final Shell aboutDialog = new Shell (shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
		aboutDialog.setSize(300, 150);
		aboutDialog.setText("About " + StudentMgt.toolTextSmall);

		//Label lblImage = new Label(aboutDialog, SWT.NONE);
		//lblImage.setImage(iconImage);
		//lblImage.setBounds(10, 10, 40, 35); //len1,ht1,len2,ht2

		//new Label (shell, SWT.SEPARATOR | SWT.HORIZONTAL);
		Label lblAboutDialog = new Label(aboutDialog, SWT.WRAP);
		lblAboutDialog.setBounds(10, 10, 270, 80); //len1,ht1,len2,ht2
		lblAboutDialog.setText(StudentMgt.toolText + " " + StudentMgt.toolVersion + "\n\n" +
				"(c) Copyright 2009 ERplan Consulting. All rights reserved.");

	    final Button btnAboutDialogOK = new Button (aboutDialog, SWT.PUSH | SWT.BUTTON1);
		btnAboutDialogOK.setText("OK");
		btnAboutDialogOK.setBounds(235, 90, 50, 25);
		Listener okButtonListener = new Listener () {
			public void handleEvent (Event event) {
				aboutDialog.close();
			}
		};
		btnAboutDialogOK.addListener (SWT.Selection, okButtonListener);

		Rectangle aboutDialogRect = aboutDialog.getBounds();
		Rectangle displayRect = display.getBounds();
	    int aboutDialogX = (displayRect.width - aboutDialogRect.width) / 2;
	    int aboutDialogY = (displayRect.height - aboutDialogRect.height) / 2;
	    aboutDialog.setLocation(aboutDialogX, aboutDialogY);

	    aboutDialog.open();
		while (!aboutDialog.isDisposed ()) {
			if (!display.readAndDispatch ()) display.sleep ();
		}
	}

}